/*
https://leetcode.cn/problems/minimum-size-subarray-sum/submissions/562528354/
滑动窗口
长度最小的子数组
*/


class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int result = INT_MAX;
        int sum=0;
        int i=0;
        int n=0;//滑动窗口的长度
        for(int j = 0;j<nums.size();j++)
        {
            sum += nums[j];
            while(sum>=target)
            {
                n=j-i+1;
                result=result < n ? result : n;
                sum-=nums[i++];
            }
        }
        return result == INT_MAX ? 0 : result;
    }
};